package org.easymodelers.gmf.update;

import java.util.HashMap;
import java.util.Map;

import org.easymodelers.gmf.data.GmfModelerData;
import org.easymodelers.modeler.loader.ModelerDataLoader;

public class ModelerInformationUpdate extends ExpressionBasedGenUpdate {
	private GmfModelerData modelerData;

	public ModelerInformationUpdate() {
	}

	public void setModelerData(GmfModelerData modelerData) {
		this.modelerData = modelerData;
	
		Map<String, Object> expressions = new HashMap<String, Object>();
		
		// On Gen Editor Generator

		String copyrightText = modelerData.getCopyrightText();
		if (isValueForFieldNotEmpty(copyrightText)) {
			expressions.put("${gmfgen:GenEditorGenerator.copyrightText}", copyrightText);
		}
		String diagramFileExtension = modelerData.getDiagramFileExtension();
		if (isValueForFieldNotEmpty(diagramFileExtension)) {
			expressions.put("${gmfgen:GenEditorGenerator.diagramFileExtension}", diagramFileExtension);
		}
		String domainFileExtension = modelerData.getDomainFileExtension();
		if (isValueForFieldNotEmpty(domainFileExtension)) {
			expressions.put("${gmfgen:GenEditorGenerator.domainFileExtension}", domainFileExtension);
		}
		String modelId = modelerData.getModelId();
		if (isValueForFieldNotEmpty(modelId)) {
			expressions.put("${gmfgen:GenEditorGenerator.modelID}", modelId);
		}
		String packageNamePrefix = modelerData.getPackageNamePrefix();
		if (isValueForFieldNotEmpty(packageNamePrefix)) {
			expressions.put("${gmfgen:GenEditorGenerator.packageNamePrefix}", packageNamePrefix);
		}

		// On Gen Plugin

		String pluginActivatorClassName = modelerData.getDiagramPluginActivatorClassName();
		if (isValueForFieldNotEmpty(pluginActivatorClassName)) {
			expressions.put("${gmfgen:GenPlugin.activatorClassName}", pluginActivatorClassName);
		}
		String pluginId = modelerData.getDiagramPluginId();
		if (isValueForFieldNotEmpty(pluginId)) {
			expressions.put("${gmfgen:GenPlugin.ID}", pluginId);
		}
		String pluginName = modelerData.getDiagramPluginName();
		if (isValueForFieldNotEmpty(pluginName)) {
			expressions.put("${gmfgen:GenPlugin.name}", pluginName);
		}
		String pluginProvider = modelerData.getDiagramPluginProvider();
		if (isValueForFieldNotEmpty(pluginProvider)) {
			expressions.put("${gmfgen:GenPlugin.provider}", pluginProvider);
		}
		
		setExpressions(expressions);
	}

}
